const express = require('express')
const router = express.Router()
const Music = require('../../model/music.js')

router.get('/', (req, res, next) => {
    // mongoose.connect('mongodb://localhost:27018/vue_project', { useNewUrlParser: true, useUnifiedTopology: true }, function(err) {
    //     if (err) {
    //         console.log(err)
    //     }
    //     return
    // });
    // let song = new Music({
    //     song: '枫',
    //     singer: '周杰伦',
    //     src: '/public/music/feng.mp3'
    // });
    // song.save((err, ret) => {
    //     if (err) {
    //         console.log(err)
    //     } else {
    //         console.log(ret)
    //         return
    //     }
    // })

    Music.find().then(data => {
        res.send(data)
        console.log('可以到这里')
    })

});
router.get('/getsongs', (req, res, next) => {
    let data = [{
            song: '枫',
            singer: '周杰伦',
            // src: 'http://49.234.36.18:90/music/feng.mp3'
            src: 'http://localhost:3000/music/feng.mp3'
        },
        {
            song: '发如雪',
            singer: '周杰伦',
            // src: 'http://49.234.36.18:90/music/faruxue.mp3'
            src: 'http://localhost:3000/music/faruxue.mp3'
        },
        {
            song: '黑色毛衣',
            singer: '周杰伦',
            // src: 'http://49.234.36.18:90/music/heisemaoyi.mp3'
            src: 'http://localhost:3000/music/heisemaoyi.mp3'
        },
        {
            song: '珊瑚海',
            singer: '周杰伦',
            // src: 'http://49.234.36.18:90/music/shanhuhai.mp3'
            src: 'http://localhost:3000/music/shanhuhai.mp3'
        },
        {
            song: '一路向北',
            singer: '周杰伦',
            // src: 'http://49.234.36.18:90/music/yiluxiangbei.mp3'
            src: 'http://localhost:3000/music/yiluxiangbei.mp3'
        },
        {
            song: '漂移',
            singer: '周杰伦',
            // src: 'http://49.234.36.18:90/music/piaoyi.mp3'
            src: 'http://localhost:3000/music/piaoyi.mp3'
        }, {
            song: '夜曲',
            singer: '周杰伦',
            // src: 'http://49.234.36.18:90/music/yequ.mp3'
            src: 'http://localhost:3000/music/yequ.mp3'
        }
    ]
    data.forEach(e => {
        let music = new Music({
            song: e.song,
            singer: e.singer,
            src: e.src
        })
        music.save()
    });
    res.end()
})
module.exports = router